## API Report File for "@backstage/backend-openapi-utils"

> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).

```ts
import type { ContentObject } from 'openapi3-ts';
import type core from 'express-serve-static-core';
import { Express as Express_2 } from 'express';
import { FromSchema } from 'json-schema-to-ts';
import { JSONSchema } from 'json-schema-to-ts';
import { middleware } from 'express-openapi-validator';
import type { OpenAPIObject } from 'openapi3-ts';
import type { ParameterObject } from 'openapi3-ts';
import type { ReferenceObject } from 'openapi3-ts';
import type { RequestBodyObject } from 'openapi3-ts';
import { RequestHandler } from 'express';
import type { ResponseObject } from 'openapi3-ts';
import { Router } from 'express';
import type { SchemaObject } from 'openapi3-ts';
import { Server } from 'http';

// @public
export interface ApiRouter<Doc extends RequiredDoc> extends Router {
  // (undocumented)
  all: DocRequestMatcher<Doc, this, 'all'>;
  // (undocumented)
  delete: DocRequestMatcher<Doc, this, 'delete'>;
  // (undocumented)
  get: DocRequestMatcher<Doc, this, 'get'>;
  // (undocumented)
  head: DocRequestMatcher<Doc, this, 'head'>;
  // (undocumented)
  options: DocRequestMatcher<Doc, this, 'options'>;
  // (undocumented)
  patch: DocRequestMatcher<Doc, this, 'patch'>;
  // (undocumented)
  post: DocRequestMatcher<Doc, this, 'post'>;
  // (undocumented)
  put: DocRequestMatcher<Doc, this, 'put'>;
}

// @public (undocumented)
type ComponentRef<
  Doc extends RequiredDoc,
  Type extends ComponentTypes<Doc>,
  Ref extends ImmutableReferenceObject,
> = Ref extends {
  $ref: `#/components/${Type}/${infer Name}`;
}
  ? Name extends keyof Doc['components'][Type]
    ? Doc['components'][Type][Name] extends ImmutableReferenceObject
      ? ComponentRef<Doc, Type, Doc['components'][Type][Name]>
      : Doc['components'][Type][Name]
    : never
  : never;

// @public (undocumented)
type ComponentTypes<Doc extends RequiredDoc> = Extract<
  keyof Doc['components'],
  string
>;

// @public (undocumented)
type ConvertAll<T extends ReadonlyArray<unknown>> = {
  [Index in keyof T]: T[Index] extends JSONSchema
    ? FromSchema<T[Index]>
    : T[Index];
} & {
  length: T['length'];
};

// @public (undocumented)
interface CookieObject extends ParameterObject {
  // (undocumented)
  in: 'cookie';
  // (undocumented)
  style?: 'form';
}

// @public (undocumented)
export type CookieParameters<
  Doc extends RequiredDoc,
  Path extends PathTemplate<Extract<keyof Doc['paths'], string>>,
  Method extends DocPathTemplateMethod<Doc, Path>,
> = CookieSchema<Doc, TemplateToDocPath<Doc, Path>, Method>;

// @public (undocumented)
type CookieSchema<
  Doc extends RequiredDoc,
  Path extends DocPath<Doc>,
  Method extends DocPathMethod<Doc, Path>,
> = ParametersSchema<Doc, Path, Method, ImmutableCookieObject>;

// @public
export function createValidatedOpenApiRouter<T extends RequiredDoc>(
  spec: T,
  options?: {
    validatorOptions?: Partial<Parameters<typeof middleware>['0']>;
    middleware?: RequestHandler[];
  },
): ApiRouter<T>;

// @public (undocumented)
type DiscriminateUnion<T, K extends keyof T, V extends T[K]> = Extract<
  T,
  Record<K, V>
>;

// @public (undocumented)
type DocOperation<
  Doc extends RequiredDoc,
  Path extends DocPath<Doc>,
  Method extends keyof Doc['paths'][Path],
> = Doc['paths'][Path][Method];

// @public (undocumented)
type DocParameter<
  Doc extends RequiredDoc,
  Path extends DocPath<Doc>,
  Method extends DocPathMethod<Doc, Path>,
  Parameter extends keyof DocOperation<Doc, Path, Method>['parameters'],
> = DocOperation<
  Doc,
  Path,
  Method
>['parameters'][Parameter] extends ImmutableReferenceObject
  ? 'parameters' extends ComponentTypes<Doc>
    ? ComponentRef<
        Doc,
        'parameters',
        DocOperation<Doc, Path, Method>['parameters'][Parameter]
      >
    : never
  : DocOperation<Doc, Path, Method>['parameters'][Parameter];

// @public (undocumented)
type DocParameters<
  Doc extends RequiredDoc,
  Path extends Extract<keyof Doc['paths'], string>,
  Method extends keyof Doc['paths'][Path],
> = {
  [Index in keyof DocOperation<
    Doc,
    Path,
    Method
  >['parameters'] as FromNumberStringToNumber<Index>]: DocParameter<
    Doc,
    Path,
    Method,
    Index
  >;
};

// @public
type DocPath<Doc extends PathDoc> = Extract<keyof Doc['paths'], string>;

// @public (undocumented)
type DocPathMethod<
  Doc extends Pick<RequiredDoc, 'paths'>,
  Path extends DocPath<Doc>,
> = keyof Doc['paths'][Path];

// @public (undocumented)
type DocPathTemplate<Doc extends PathDoc> = PathTemplate<DocPath<Doc>>;

// @public (undocumented)
type DocPathTemplateMethod<
  Doc extends Pick<RequiredDoc, 'paths'>,
  Path extends DocPathTemplate<Doc>,
> = keyof Doc['paths'][TemplateToDocPath<Doc, Path>];

// @public
type DocRequestHandler<
  Doc extends RequiredDoc,
  Path extends DocPath<Doc>,
  Method extends DocPathMethod<Doc, Path>,
> = core.RequestHandler<
  PathSchema<Doc, Path, Method>,
  ResponseBodyToJsonSchema<Doc, Path, Method>,
  RequestBodyToJsonSchema<Doc, Path, Method>,
  QuerySchema<Doc, Path, Method>,
  Record<string, string>
>;

// @public
type DocRequestHandlerParams<
  Doc extends RequiredDoc,
  Path extends DocPath<Doc>,
  Method extends DocPathMethod<Doc, Path>,
> = core.RequestHandlerParams<
  PathSchema<Doc, Path, Method>,
  ResponseBodyToJsonSchema<Doc, Path, Method>,
  RequestBodyToJsonSchema<Doc, Path, Method>,
  QuerySchema<Doc, Path, Method>,
  Record<string, string>
>;

// @public
interface DocRequestMatcher<
  Doc extends RequiredDoc,
  T,
  Method extends
    | 'all'
    | 'get'
    | 'post'
    | 'put'
    | 'delete'
    | 'patch'
    | 'options'
    | 'head',
> {
  // (undocumented)
  <
    Path extends MethodAwareDocPath<
      Doc,
      PathTemplate<Extract<keyof Doc['paths'], string>>,
      Method
    >,
  >(
    path: Path,
    ...handlers: Array<
      DocRequestHandler<Doc, TemplateToDocPath<Doc, Path>, Method>
    >
  ): T;
  // (undocumented)
  <
    Path extends MethodAwareDocPath<
      Doc,
      PathTemplate<Extract<keyof Doc['paths'], string>>,
      Method
    >,
  >(
    path: Path,
    ...handlers: Array<
      DocRequestHandlerParams<Doc, TemplateToDocPath<Doc, Path>, Method>
    >
  ): T;
}

// @public (undocumented)
type Filter<T, U> = T extends U ? T : never;

// @public
type FromNumberStringToNumber<NumberString extends string | number | symbol> =
  NumberString extends `${infer R extends number}` ? R : never;

// @public (undocumented)
type FullMap<
  T extends {
    [key: string]: any;
  },
> = RequiredMap<T> & OptionalMap<T>;

// @public
export function getOpenApiSpecRoute(baseUrl: string): string;

// @public (undocumented)
interface HeaderObject extends ParameterObject {
  // (undocumented)
  in: 'header';
  // (undocumented)
  style: 'simple';
}

// @public (undocumented)
export type HeaderParameters<
  Doc extends RequiredDoc,
  Path extends PathTemplate<Extract<keyof Doc['paths'], string>>,
  Method extends DocPathTemplateMethod<Doc, Path>,
> = HeaderSchema<Doc, TemplateToDocPath<Doc, Path>, Method>;

// @public (undocumented)
type HeaderSchema<
  Doc extends RequiredDoc,
  Path extends DocPath<Doc>,
  Method extends DocPathMethod<Doc, Path>,
> = ParametersSchema<Doc, Path, Method, ImmutableHeaderObject>;

// @public
type Immutable<T> = T extends
  | Function
  | boolean
  | number
  | string
  | null
  | undefined
  ? T
  : T extends Map<infer K, infer V>
  ? ReadonlyMap<Immutable<K>, Immutable<V>>
  : T extends Set<infer S>
  ? ReadonlySet<Immutable<S>>
  : {
      readonly [P in keyof T]: Immutable<T[P]>;
    };

// @public (undocumented)
type ImmutableContentObject = ImmutableObject<ContentObject>;

// @public (undocumented)
type ImmutableCookieObject = ImmutableObject<CookieObject>;

// @public (undocumented)
type ImmutableHeaderObject = ImmutableObject<HeaderObject>;

// @public (undocumented)
type ImmutableObject<T> = {
  readonly [K in keyof T]: Immutable<T[K]>;
};

// @public (undocumented)
type ImmutableOpenAPIObject = ImmutableObject<OpenAPIObject>;

// @public (undocumented)
type ImmutableParameterObject = ImmutableObject<ParameterObject>;

// @public (undocumented)
type ImmutablePathObject = ImmutableObject<PathObject>;

// @public (undocumented)
type ImmutableQueryObject = ImmutableObject<QueryObject>;

// @public (undocumented)
type ImmutableReferenceObject = ImmutableObject<ReferenceObject>;

// @public (undocumented)
type ImmutableRequestBodyObject = ImmutableObject<RequestBodyObject>;

// @public (undocumented)
type ImmutableResponseObject = ImmutableObject<ResponseObject>;

// @public (undocumented)
type ImmutableSchemaObject = ImmutableObject<SchemaObject>;

declare namespace internal {
  export {
    RequiredDoc,
    PathDoc,
    ValueOf,
    DocPath,
    PathTemplate,
    TemplateToDocPath,
    DocPathTemplate,
    DocPathMethod,
    DocPathTemplateMethod,
    MethodAwareDocPath,
    DocOperation,
    ComponentTypes,
    ComponentRef,
    SchemaRef,
    ObjectWithContentSchema,
    UnionToIntersection,
    LastOf,
    Push,
    TuplifyUnion,
    ConvertAll,
    UnknownIfNever,
    ToTypeSafe,
    DiscriminateUnion,
    MapDiscriminatedUnion,
    PickOptionalKeys,
    PickRequiredKeys,
    OptionalMap,
    RequiredMap,
    FullMap,
    Filter,
    DocRequestHandler,
    DocRequestHandlerParams,
    DocRequestMatcher,
    Immutable,
    ImmutableObject,
    ImmutableReferenceObject,
    ImmutableOpenAPIObject,
    ImmutableContentObject,
    ImmutableRequestBodyObject,
    ImmutableResponseObject,
    ImmutableParameterObject,
    HeaderObject,
    ImmutableHeaderObject,
    CookieObject,
    ImmutableCookieObject,
    QueryObject,
    ImmutableQueryObject,
    PathObject,
    ImmutablePathObject,
    ImmutableSchemaObject,
    DocParameter,
    FromNumberStringToNumber,
    DocParameters,
    ParameterSchema,
    MapToSchema,
    ParametersSchema,
    HeaderSchema,
    CookieSchema,
    PathSchema,
    QuerySchema,
    RequestBody,
    RequestBodySchema,
    RequestBodyToJsonSchema,
    Response_3 as Response,
    ResponseSchemas,
    ResponseBodyToJsonSchema,
  };
}
export { internal };

// @public (undocumented)
type LastOf<T> = UnionToIntersection<
  T extends any ? () => T : never
> extends () => infer R
  ? R
  : never;

// @public (undocumented)
type MapDiscriminatedUnion<T extends Record<K, string>, K extends keyof T> = {
  [V in T[K]]: DiscriminateUnion<T, K, V>;
};

// @public (undocumented)
type MapToSchema<
  Doc extends RequiredDoc,
  T extends Record<string, ImmutableParameterObject>,
> = {
  [V in keyof T]: NonNullable<T[V]> extends ImmutableParameterObject
    ? ParameterSchema<Doc, NonNullable<T[V]>['schema']>
    : never;
};

// @public (undocumented)
type MethodAwareDocPath<
  Doc extends PathDoc,
  Path extends DocPathTemplate<Doc>,
  Method extends DocPathTemplateMethod<Doc, Path>,
> = ValueOf<{
  [Template in DocPath<Doc>]: Path extends PathTemplate<Template>
    ? Method extends DocPathTemplateMethod<Doc, Path>
      ? PathTemplate<Template>
      : never
    : never;
}>;

// @public (undocumented)
type ObjectWithContentSchema<
  Doc extends RequiredDoc,
  Object extends {
    content?: ImmutableContentObject;
  },
> = Object['content'] extends ImmutableContentObject
  ? SchemaRef<Doc, Object['content']['application/json']['schema']>
  : never;

// @public (undocumented)
type OptionalMap<
  T extends {
    [key: string]: any;
  },
> = {
  [P in Exclude<PickOptionalKeys<T>, undefined>]?: NonNullable<T[P]>;
};

// @public (undocumented)
type ParameterSchema<
  Doc extends RequiredDoc,
  Schema extends ImmutableParameterObject['schema'],
> = SchemaRef<Doc, Schema> extends infer R
  ? R extends ImmutableSchemaObject
    ? R extends JSONSchema
      ? FromSchema<R>
      : never
    : never
  : never;

// @public (undocumented)
type ParametersSchema<
  Doc extends RequiredDoc,
  Path extends Extract<keyof Doc['paths'], string>,
  Method extends keyof Doc['paths'][Path],
  FilterType extends ImmutableParameterObject,
> = MapToSchema<
  Doc,
  FullMap<
    MapDiscriminatedUnion<
      Filter<ValueOf<DocParameters<Doc, Path, Method>>, FilterType>,
      'name'
    >
  >
>;

// @public (undocumented)
type PathDoc = Pick<ImmutableOpenAPIObject, 'paths'>;

// @public (undocumented)
interface PathObject extends ParameterObject {
  // (undocumented)
  in: 'path';
  // (undocumented)
  style?: 'simple' | 'label' | 'matrix';
}

// @public (undocumented)
export type PathParameters<
  Doc extends RequiredDoc,
  Path extends PathTemplate<Extract<keyof Doc['paths'], string>>,
  Method extends DocPathTemplateMethod<Doc, Path>,
> = PathSchema<Doc, TemplateToDocPath<Doc, Path>, Method>;

// @public (undocumented)
type PathSchema<
  Doc extends RequiredDoc,
  Path extends DocPath<Doc>,
  Method extends DocPathMethod<Doc, Path>,
> = ParametersSchema<Doc, Path, Method, ImmutablePathObject>;

// @public
type PathTemplate<Path extends string> =
  Path extends `${infer Prefix}{${infer PathName}}${infer Suffix}`
    ? `${Prefix}:${PathName}${PathTemplate<Suffix>}`
    : Path;

// @public (undocumented)
type PickOptionalKeys<
  T extends {
    [key: string]: any;
  },
> = {
  [K in keyof T]: true extends T[K]['required'] ? never : K;
}[keyof T];

// @public (undocumented)
type PickRequiredKeys<
  T extends {
    [key: string]: any;
  },
> = {
  [K in keyof T]: true extends T[K]['required'] ? K : never;
}[keyof T];

// @public (undocumented)
type Push<T extends any[], V> = [...T, V];

// @public (undocumented)
interface QueryObject extends ParameterObject {
  // (undocumented)
  in: 'query';
  // (undocumented)
  style?: 'form' | 'deepObject' | 'pipeDelimited' | 'spaceDelimited';
}

// @public (undocumented)
export type QueryParameters<
  Doc extends RequiredDoc,
  Path extends PathTemplate<Extract<keyof Doc['paths'], string>>,
  Method extends DocPathTemplateMethod<Doc, Path>,
> = QuerySchema<Doc, TemplateToDocPath<Doc, Path>, Method>;

// @public (undocumented)
type QuerySchema<
  Doc extends RequiredDoc,
  Path extends DocPath<Doc>,
  Method extends DocPathMethod<Doc, Path>,
> = ParametersSchema<Doc, Path, Method, ImmutableQueryObject>;

// @public (undocumented)
type Request_2<
  Doc extends RequiredDoc,
  Path extends PathTemplate<Extract<keyof Doc['paths'], string>>,
  Method extends DocPathTemplateMethod<Doc, Path>,
> = RequestBodyToJsonSchema<Doc, TemplateToDocPath<Doc, Path>, Method>;
export { Request_2 as Request };

// @public (undocumented)
type RequestBody<
  Doc extends RequiredDoc,
  Path extends Extract<keyof Doc['paths'], string>,
  Method extends keyof Doc['paths'][Path],
> = DocOperation<
  Doc,
  Path,
  Method
>['requestBody'] extends ImmutableReferenceObject
  ? 'requestBodies' extends ComponentTypes<Doc>
    ? ComponentRef<
        Doc,
        'requestBodies',
        DocOperation<Doc, Path, Method>['requestBody']
      >
    : never
  : DocOperation<Doc, Path, Method>['requestBody'];

// @public (undocumented)
type RequestBodySchema<
  Doc extends RequiredDoc,
  Path extends DocPath<Doc>,
  Method extends DocPathMethod<Doc, Path>,
> = RequestBody<Doc, Path, Method> extends ImmutableRequestBodyObject
  ? ObjectWithContentSchema<Doc, RequestBody<Doc, Path, Method>>
  : never;

// @public
type RequestBodyToJsonSchema<
  Doc extends RequiredDoc,
  Path extends DocPath<Doc>,
  Method extends DocPathMethod<Doc, Path>,
> = ToTypeSafe<RequestBodySchema<Doc, Path, Method>>;

// @public
type RequiredDoc = Pick<ImmutableOpenAPIObject, 'paths' | 'components'>;

// @public (undocumented)
type RequiredMap<
  T extends {
    [key: string]: any;
  },
> = {
  [P in Exclude<PickRequiredKeys<T>, undefined>]: NonNullable<T[P]>;
};

// @public (undocumented)
type Response_2<
  Doc extends RequiredDoc,
  Path extends PathTemplate<Extract<keyof Doc['paths'], string>>,
  Method extends DocPathTemplateMethod<Doc, Path>,
> = ResponseBodyToJsonSchema<Doc, TemplateToDocPath<Doc, Path>, Method>;
export { Response_2 as Response };

// @public (undocumented)
type Response_3<
  Doc extends RequiredDoc,
  Path extends DocPath<Doc>,
  Method extends DocPathMethod<Doc, Path>,
  StatusCode extends keyof DocOperation<Doc, Path, Method>['responses'],
> = DocOperation<
  Doc,
  Path,
  Method
>['responses'][StatusCode] extends ImmutableReferenceObject
  ? 'responses' extends ComponentTypes<Doc>
    ? ComponentRef<
        Doc,
        'responses',
        DocOperation<Doc, Path, Method>['responses'][StatusCode]
      >
    : never
  : DocOperation<Doc, Path, Method>['responses'][StatusCode];

// @public
type ResponseBodyToJsonSchema<
  Doc extends RequiredDoc,
  Path extends DocPath<Doc>,
  Method extends DocPathMethod<Doc, Path>,
> = ToTypeSafe<ValueOf<ResponseSchemas<Doc, Path, Method>>>;

// @public (undocumented)
type ResponseSchemas<
  Doc extends RequiredDoc,
  Path extends DocPath<Doc>,
  Method extends DocPathMethod<Doc, Path>,
> = {
  [StatusCode in keyof DocOperation<
    Doc,
    Path,
    Method
  >['responses']]: Response_3<
    Doc,
    Path,
    Method,
    StatusCode
  > extends ImmutableResponseObject
    ? ObjectWithContentSchema<Doc, Response_3<Doc, Path, Method, StatusCode>>
    : never;
};

// @public (undocumented)
type SchemaRef<Doc extends RequiredDoc, Schema> = Schema extends {
  $ref: `#/components/schemas/${infer Name}`;
}
  ? 'schemas' extends keyof Doc['components']
    ? Name extends keyof Doc['components']['schemas']
      ? SchemaRef<Doc, Doc['components']['schemas'][Name]>
      : never
    : never
  : {
      [Key in keyof Schema]: SchemaRef<Doc, Schema[Key]>;
    };

// @public
type TemplateToDocPath<
  Doc extends PathDoc,
  Path extends DocPathTemplate<Doc>,
> = ValueOf<{
  [Template in DocPath<Doc>]: Path extends PathTemplate<Template>
    ? Template
    : never;
}>;

// @public (undocumented)
type ToTypeSafe<T> = UnknownIfNever<ConvertAll<TuplifyUnion<T>>[number]>;

// @public (undocumented)
type TuplifyUnion<
  T,
  L = LastOf<T>,
  N = [T] extends [never] ? true : false,
> = true extends N ? [] : Push<TuplifyUnion<Exclude<T, L>>, L>;

// @public
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
  k: infer I,
) => void
  ? I
  : never;

// @public (undocumented)
type UnknownIfNever<P> = [P] extends [never] ? unknown : P;

// @public
type ValueOf<T> = T[keyof T];

// @public
export const wrapInOpenApiTestServer: (app: Express_2) => Server | Express_2;
```
